package WebServices;

import java.util.List;

import dbindex.DocTable;
import dbindex.Language;

import guislicer.SimilarDocSelector;
import wikipedia.util.Encodings;

public class Edoc 
{
    // try: 
    // http://192.168.0.101:8080/axis/Edoc.jws?wsdl
    // http://192.168.0.102/ksnet2/scripts/DOC/client_edoc.php
    //
	public static void main(String[] args)
	{
        String  title;
        String ksnetcontext_db, ksnetcontext_user, ksnetcontext_pass;
        String wiki_host, wiki_db, wiki_user, wiki_pass;
        
        int     onto_id = 139; // Disaster (AO)
        
        //Language lang = Language.ENGLISH;
        Language lang = Language.RUSSIAN;
        
        if(Language.ENGLISH == lang) {

            ksnetcontext_db     = "192.168.0.101:3306/ksnetcontext";
            ksnetcontext_user   = "michael";
            ksnetcontext_pass   = "12345";

            wiki_host   = "192.168.0.29";
            wiki_db     = "enwiki?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useUnbufferedInput=false";
            wiki_user   = "javawiki";
            wiki_pass   =  "";

            title = "Emergency_evacuation";
        } else {

            // russian
            title = "Методы_противопожарной_защиты";
            //title = "Авиакатастрофы";
            //title = "Лавина";

            ksnetcontext_db     = "192.168.0.101:3306/ksnetcontext_ru";
            ksnetcontext_user   = "michael";
            ksnetcontext_pass   = "12345";
            
            wiki_host   = "192.168.0.29";
            wiki_db     = "ruwiki?useUnicode=false&characterEncoding=ISO8859_1&autoReconnect=true&useUnbufferedInput=false";
            wiki_user   = "javawiki";
            wiki_pass   =  "";
        }
        
		System.out.println( Edoc.Sorted(onto_id, lang.toInt(),
                ksnetcontext_db, ksnetcontext_user, ksnetcontext_pass, 
                wiki_host, wiki_db, wiki_user, wiki_pass, 
                title) );
	}

	public static String Sorted(
            int     onto_id,
            int lang_id,
            String  ksnetcontext_db,String ksnetcontext_user,String ksnetcontext_pass,
            String  wiki_host,String wiki_db,String wiki_user,String wiki_pass, 
            String  title)
	{
        Language lang = Language.get(lang_id);
                
        System.out.println("\n Parameters:");
		System.out.println("    onto_id: "   +  onto_id );
        System.out.println("    lang_id="+lang.toInt() + " ("+lang.toString()+")");
		System.out.println("    title: "     +  title + "\n");
        
        System.out.println("    Three parameters related to the index database: (ksnetcontext[_ru])");
        System.out.println("    name = " + ksnetcontext_db);
        System.out.println("    user = " + ksnetcontext_user);
        System.out.println("    pass = " + ksnetcontext_pass + "\n");

        System.out.println("    Four parameters related to the Wikipedia database:");
        System.out.println("    ip      = " + wiki_host);
        System.out.println("    params  = " + wiki_db);
        System.out.println("    user    = " + wiki_user);
        System.out.println("    pass    = " + wiki_pass + "\n");
        
        /*String s;
        s = Encodings.FromTo(title, "UTF8", "Cp1251"); System.out.println("UTF8 to Cp1251 : " + s);
        s = Encodings.FromTo(title, "Cp1251", "UTF8"); System.out.println("Cp1251 to UTF8 : " + s);
        
        return ksnetcontext_db + ksnetcontext_user + ksnetcontext_pass + wiki_host + wiki_db + wiki_user + wiki_pass+ title;
        */        
        List<DocTable> docs = SimilarDocSelector.selectFromWikiByDocName(onto_id,
                ksnetcontext_db,ksnetcontext_user,ksnetcontext_pass,lang,
                wiki_host,wiki_db,wiki_user,wiki_pass,title);
        
        String s = SimilarDocSelector.getXML(docs);
        System.out.println(s);
        return s;
		//return "Hey, hello";
	}
}
